/**************************************************************************
 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

//-------------------------------------------------------------------------
//     Analysis Oriented Data (AOD) 3LH vertex class
//     Authors: B.Hippolyte, IReS, hippolyt@in2p3.fr 
//              G.Van Buren, BNL,  gene@bnl.gov      (original STAR MuDsts)
//-------------------------------------------------------------------------
#include "/home/ramona/ANALISI/TestRiduzione/NewTask/TipoMuoni/Test1/AliAOD3LH.h"

//#include <AliAOD3LH.h>
#include "AliAODTrack.h"
#include "AliESDv0.h"
#include "AliAODVertex.h"

ClassImp(AliAOD3LH)

  AliAOD3LH::AliAOD3LH() : 
    AliAODRecoDecay(),
    fDca3LHToPrimVertex(999),
    fOnFlyStatus(kFALSE)
{
}

//CHECk this thinks!

AliAOD3LH::AliAOD3LH(const AliESDv0& rv0vertex,AliAODVertex* fAODvertex,Double_t d0[2]):
AliAODRecoDecay(fAODvertex,2,0,d0),  
  fDca3LHToPrimVertex(0),
  fOnFlyStatus(kFALSE)
{
  
  //COSTRUCTOR Ramona

  fCharge  = 0;
  fNProngs = 2;
  fNDCA    = 1;
  fNPID    = 0; // used to be 2!

  fDCA = new Double_t[fNDCA];

  fDCA[0] = rv0vertex.GetDcaV0Daughters(); //dca tracks
  fDca3LHToPrimVertex = rv0vertex.GetD(fAODvertex->GetX(),fAODvertex->GetY(),fAODvertex->GetZ()); // dca v0 to PV

  fPx = new Double_t[GetNProngs()];
  fPy = new Double_t[GetNProngs()];
  fPz = new Double_t[GetNProngs()];

  rv0vertex.GetPPxPyPz(fPx[0], fPy[0], fPz[0]);
  rv0vertex.GetNPxPyPz(fPx[1], fPy[1], fPz[1]);

  // fPx[0] = rMomPos[0];  //px,py,pz track1
  // fPy[0] = rMomPos[1];
  // fPz[0] = rMomPos[2];

  // fPx[1] = rMomNeg[0]; //px,py,pz track2
  // fPy[1] = rMomNeg[1];
  // fPz[1] = rMomNeg[2];
  
}


AliAOD3LH::AliAOD3LH(AliAODVertex* rAODVertex, Double_t rDca3LHDaughters, Double_t rDca3LHToPrimVertex,
	   const Double_t *rMomPos, const Double_t *rMomNeg, Double_t *rDcaDaughterToPrimVertex) :
  AliAODRecoDecay(rAODVertex,2,0,rDcaDaughterToPrimVertex),
  fDca3LHToPrimVertex(rDca3LHToPrimVertex),
  fOnFlyStatus(kFALSE)
{
  //--------------------------------------------------------------------
  // Constructor via setting each data member
  //--------------------------------------------------------------------
  fCharge  = 0;
  fNProngs = 2;
  fNDCA    = 1;
  fNPID    = 0; // used to be 2!

  fDCA = new Double_t[fNDCA];

  fDCA[0] = rDca3LHDaughters;
  fDca3LHToPrimVertex = rDca3LHToPrimVertex;

  fPx = new Double_t[GetNProngs()];
  fPy = new Double_t[GetNProngs()];
  fPz = new Double_t[GetNProngs()];

  fPx[0] = rMomPos[0] ;
  fPy[0] = rMomPos[1];
  fPz[0] = rMomPos[2];

  fPx[1] = rMomNeg[0];
  fPy[1] = rMomNeg[1];
  fPz[1] = rMomNeg[2];
}

AliAOD3LH::AliAOD3LH(const AliAOD3LH& rAliAOD3LH) :
  AliAODRecoDecay(rAliAOD3LH),
  fDca3LHToPrimVertex(rAliAOD3LH.fDca3LHToPrimVertex),
  fOnFlyStatus(rAliAOD3LH.fOnFlyStatus)
 {
  //--------------------------------------------------------------------
  // Copy constructor
  //--------------------------------------------------------------------
}

AliAOD3LH& AliAOD3LH::operator=(const AliAOD3LH& rAliAOD3LH){
  //--------------------------------------------------------------------
  // Assignment overload
  //--------------------------------------------------------------------
  if(this!=&rAliAOD3LH) {
    AliAODRecoDecay::operator=(rAliAOD3LH);
    fDca3LHToPrimVertex  = rAliAOD3LH.fDca3LHToPrimVertex ;
    fOnFlyStatus         = rAliAOD3LH.fOnFlyStatus;
  }
  return *this;
}

AliAOD3LH::~AliAOD3LH(){
  //--------------------------------------------------------------------
  // Empty destructor
  //--------------------------------------------------------------------
}

void AliAOD3LH::Fill(AliAODVertex *rAODVertex, Double_t rDca3LHDaughters, Double_t rDca3LHToPrimVertex,
		     const Double_t *rMomPos, const Double_t *rMomNeg, const Double_t *rDcaDaughterToPrimVertex){
  //--------------------------------------------------------------------
  // Filling with all needed info
  //--------------------------------------------------------------------
  this->SetSecondaryVtx(rAODVertex);

  fDCA[0] = rDca3LHDaughters;
  fDca3LHToPrimVertex = rDca3LHToPrimVertex;

  fPx[0] = rMomPos[0] ;
  fPy[0] = rMomPos[1];
  fPz[0] = rMomPos[2];

  fPx[1] = rMomNeg[0];
  fPy[1] = rMomNeg[1];
  fPz[1] = rMomNeg[2];

  fd0[0] = rDcaDaughterToPrimVertex[0];
  fd0[1] = rDcaDaughterToPrimVertex[1];
}

void AliAOD3LH::Reset3LH(){
  //--------------------------------------------------------------------
  // Resetting all the info
  //--------------------------------------------------------------------
  GetSecondaryVtx()->SetChi2perNDF(999);
  GetSecondaryVtx()->RemoveCovMatrix();
  GetSecondaryVtx()->RemoveDaughters();
  GetSecondaryVtx()->SetParent((TObject*) 0x0);
  GetSecondaryVtx()->SetID(-1);
  GetSecondaryVtx()->SetPosition(999,999,999);
  GetSecondaryVtx()->SetType(AliAODVertex::kUndef);

  fDCA[0] = 999;
  fDca3LHToPrimVertex  = 999;

  fPx[0] = 999;
  fPy[0] = 999;
  fPz[0] = 999;

  fPx[1] = 999;
  fPy[1] = 999;
  fPz[1] = 999;

  fd0[0] = 999;
  fd0[1] = 999;
}

Short_t AliAOD3LH::GetPosID() const {
  AliAODTrack *posTrack = (AliAODTrack *) (this->GetSecondaryVtx()->GetDaughter(0));
  Short_t posID = posTrack->GetID();
  return posID;
}

Short_t AliAOD3LH::GetNegID() const {
  AliAODTrack *negTrack = (AliAODTrack *) (this->GetSecondaryVtx()->GetDaughter(1));
  Short_t negID = negTrack->GetID();
  return negID;
}

void AliAOD3LH::Print(Option_t* /*option*/) const {
  //
  // Print some information
  //
  AliAODRecoDecay::Print();
  printf("AliAOD3LH: invariant mass (k0s %.6f, lambda %.6f, anti-lambda %.6f) \n",MassK0Short(),MassLambda(),MassAntiLambda());
  printf("AliAOD3LH: dca (3LHd %.6f, 3LHtpv %.6f, postpv %.6f, negtpv %.6f ) \n",Dca3LHDaughters(),Dca3LHToPrimVertex(),DcaPosToPrimVertex(),DcaNegToPrimVertex());
  printf("AliAOD3LH: mom (ptot2 %.6f, pt2 %.6f, rapk0 %.6f, rapla %.6f ) \n",Ptot23LH(),Pt23LH(),RapK0Short(),RapLambda());
  printf("AliAOD3LH: cin (mpa3LH %.6f, mna3LH %.6f, alpha %.6f, ptarm %.6f ) \n",MomPosAlong3LH(),MomNegAlong3LH(),Alpha3LH(),PtArm3LH());
  printf("AliAOD3LH: nrg (eppro %.6f, enpro %.6f, eppio %.6f, enpio %.6f ) \n",EPosProton(),ENegProton(),EPosPion(),ENegPion());

  return;
}
